const config = require('./config');
const web3 = require("@solana/web3.js");
const bip39 = require('bip39');
import { derivePath } from 'ed25519-hd-key';


const keypairFromMne = () => {

    const mnemonic =
        "neither lonely flavor argue grass remind eye tag avocado spot unusual intact";
    const seed = bip39.mnemonicToSeedSync(mnemonic, ""); // (mnemonic, password)


    for (let i = 0; i < 10; i++) {
        const path = `m/44'/501'/${i}'/0'`;
        const seedWords = derivePath(path, seed.toString("hex")).key;

        const seedWordsStr = seedWords.toString('hex');
        console.log('seedWords: ', seedWordsStr);

        const keypair = web3.Keypair.fromSeed(seedWordsStr);
        console.log(`${path} => ${keypair.publicKey.toBase58()}`);
    }
}
const keyPairFromSeed = ()=>{
    const seedWord = "95756468025e5f69cf191815b443d5aedf7f6d613ef729b3e2a3031fd7aa4f31";
    const keypair = web3.Keypair.fromSeed(seedWord);
    console.log(` => ${keypair.publicKey.toBase58()}`);
}

//keypairFromMne();

//keyPairFromSeed();

const getKeypair = () => {
    const seed = bip39.mnemonicToSeedSync(config.wallet.words, "");
    const seedWords = derivePath(config.wallet.path, seed.toString('hex')).key;
    const seedWordStr = seedWords.toString('hex');
    const keypair = web3.Keypair.fromSeed(seedWordStr);
    console.log(`${keypair.publicKey.toBase58()}`);

    return keypair;


}

//getKeypair();

module.exports = getKeypair;




